#include <bits/stdc++.h>
#define N 200005
using namespace std;
typedef long long ll;

int n, m, Q;
bool vst[N], dfn[N];
vector <int> to[N];

struct es { int u, v; } e[N];

void dfs (int u, int fa)
{
    dfn[u]=1;
    for (int i=0; i<(int)to[u].size(); i++) {
        if (vst[to[u][i]]) { continue; }
        int v=(e[to[u][i]].u==u ? e[to[u][i]].v : e[to[u][i]].u);
        if (v==fa || dfn[v]) { continue; }
        dfs(v, u);
    }
}

int main ()
{
    freopen("graph.in", "r", stdin);
    freopen("graph.out", "w", stdout);
    
    scanf("%d %d", &n, &m);
    for (int i=1; i<=m; i++) {
        scanf("%d %d", &e[i].u, &e[i].v);
        to[e[i].u].push_back(i);
        to[e[i].v].push_back(i);
    }

    scanf("%d", &Q);
    for (int t=1; t<=Q; t++) {
        int k; scanf("%d", &k);
        fill(vst+1, vst+m+1, 0);
        fill(dfn+1, dfn+m+1, 0);
        for (int i=1; i<=k; i++) {
            int id; scanf("%d", &id); vst[id]=1;
        }

        dfs(1, 0);

        bool ok=1;
        for (int i=1; i<=n; i++) if (!dfn[i]) { ok=0; break; }
        if (ok) { printf("YES\n"); }
        else { printf("NO\n"); }
    }

    return 0;
}